﻿using FasterWPF;
using FasterWPFDemo.UserControls;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reactive;
using System.Reactive.Subjects;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
using FasterWPF.Observables;

namespace FasterWPFDemo
{
    //Plain DataGrid
    public partial class TabItem08 : UserControl, IUserControlGuid
    {
        private void a_Click(object sender, RoutedEventArgs e)
        {
            //!!! need to support more than one column index to sort on!!!

            DataGridSort dga = new DataGridSort(0);

            //this just handles more than one textblock within a composite to sort on
            dg.SortByText1AndThenBy2(dga, 0, 0, 1, 0, CommonExt.SortOrder.Desc, CommonExt.SortOrder.Asc, CommonExt.SortControlType.TextBlock);


            //CPSWindow mainWindow = Selectors.RecurseUpParentFrameworkElementsUntilType(false, 100, dg, "CPSWindow") as CPSWindow;

            
            //ComboBox myBrder = mainWindow.SelectAllFrameworkElementsByClass("SilverClickParent", false).First() as ComboBox;

            ////TextBlock myChild = mainWindow.SelectAllFrameworkElementsByClass("SilverClick", false).First() as TextBlock;

            //TextBlock myChild = myBrder.GetChildFromParent<TextBlock, ComboBox>("hi", 0, 0);

            //Subject<EventPattern<MouseButtonEventArgs>> eventSubj3 = FasterWPF.ObservableHelper.GetSubjectFromParent<ComboBox>(myBrder, "hi", 0, 0, "PreviewMouseDown") as Subject<EventPattern<MouseButtonEventArgs>>;
                
            //    //(Subject<EventPattern<MouseButtonEventArgs>>)myBrder.GetSubjectFromBorder<MouseButtonEventArgs, TextBlock, ComboBox>(0, 0, "PreviewMouseDown");
            //eventSubj3.OnNext(new EventPattern<MouseButtonEventArgs>(myChild, new MouseButtonEventArgs(Mouse.PrimaryDevice, 100, MouseButton.Left)));
            //FasterWPF.Observables.ObservableHelper.FireObservableByClassName<MouseButtonEventArgs>(mainWindow, "myParentClassName", "myChildClassName", "PreviewMouseDown", Helpers.GetMouseClickArgs());

           FasterWPF.Observables.ObservableHelper.FireObservableByClassName<MouseButtonEventArgs>(dg, "hi", 0, 0, 100, "CPSWindow", "SilverClickParent", "PreviewMouseDown", Helpers.GetMouseClickArgs());

            if (FasterWPF.Observables.ObservableHelper.IsObservableAvailableByClassName<MouseButtonEventArgs>(dg, 100, "CPSWindow", "SilverClickParent", "SilverClick", "PreviewMouseDown"))
            {
                FasterWPF.Observables.ObservableHelper.FireObservableByClassName<MouseButtonEventArgs>(dg, 100, "CPSWindow", "SilverClickParent", "SilverClick", "PreviewMouseDown", new MouseButtonEventArgs(Mouse.PrimaryDevice, 100, MouseButton.Left));
            }

            

            //TO REMOVE A ROW FROM THE DATAGRID, unsubscribe child events and remove all CHILD COMPOSITES for that row. 
            //Once the last Child Composite is removed the entire row will automatically be removed.
            //dg.UnsubscribeChildEventsByKey(rowGuid7 + "1");
            //dg.UnsubscribeChildEventsByKey(rowGuid7 + "2");
            //dg.RemoveByKey(rowGuid7 + "1");
            //dg.RemoveByKey(rowGuid7 + "2");

         //   dg.RemoveAll();
             //dg.SortByText(dga, 0, 0, CommonExt.SortOrder.Desc, CommonExt.SortControlType.TextBlock);
        }
    }
}
